<template>
  <view class="address">
    <view class="no-add" v-if="JSON.stringify(address) === '{}'">
      <button @click="getAddress" type="primary" size="mini">添加收货地址+</button>
    </view>
    <view class="has-add" @click="getAddress" v-else>
      <view class="top">
        <view class="left">
          姓名：{{address.userName}}
        </view>
        <view class="right">
          电话：{{address.telNumber}}
          <uni-icons class="add-icon" type="right" size="18"></uni-icons>
        </view>
      </view>
      <view class="bottom">
         收货地址：{{fullAddress}}
      </view>
    </view>
    <image class="img" src="../../static/images/cart_border@2x.png" mode=""></image>
  </view>
</template>

<script>
  import {mapState,mapMutations,mapGetters} from 'vuex'
  export default {
    name:"my-address",
    data() {
      return {
        // address:{}
      };
    },
    computed:{
      ...mapState('user',['address']),
      ...mapGetters('user',['fullAddress'])
    },
    methods:{
      ...mapMutations('user',['setaddress']),
      async getAddress(){
      const [err,res] = await uni.chooseAddress()
      if(err) return uni.$showMsg('取消/地址无效')  
      // console.log(res);
      // this.address = res
      this.setaddress(res)
      }
    }
  }
</script>

<style lang="scss">
.address{
  .no-add{
    height: 200rpx;
    display: flex;
    justify-content: center;
    align-items: center;
  }
  .has-add{
    padding: 20rpx;
    font-size: 14px;
    .top{
      height: 60rpx;
      display: flex;
      justify-content: space-between;
      .right{
        .add-icon{
          margin-left: 10rpx;
        }
      }
    }
  }
  .img{
    height: 10rpx;
    width: 100%;
  }
}
</style>